import { reactive } from 'vue';
import router from '@/router';

export default function importConfig(props) {
  const { user } = props;
  const base = reactive<any>({
    userInfoFormRef: null,
  });

  const userInfoForm = reactive({
    nick: user.nick,
    tel: user.tel,
    email: user.email,
    sex: user.sex,
  });

  const userInfoRules = {
    nick: [{ required: true, message: '请输入昵称' }],
    tel: [{ required: true, message: '请输入手机号' }],
    email: [{ required: true, message: '请输入邮箱' }],
  };

  const userInfoList = reactive([
    {
      label: '用户昵称',
      placeholder: '请输入用户昵称',
      field: 'nick',
      required: true,
      isInput: true,
    },
    {
      label: '手机号码',
      placeholder: '请输入手机号码',
      field: 'tel',
      required: true,
      isInput: true,
    },
    {
      label: '邮箱',
      placeholder: '请输入邮箱',
      field: 'email',
      required: true,
      isInput: true,
    },
    {
      label: '性别',
      field: 'sex',
      isRadio: true,
    },
  ]);

  const save = () => {
    base.userInfoFormRef.validate((res) => {
      if (!res) {
        // console.log('1验证通过');
      }
    });
  };

  const close = () => {
    router.replace('/home');
  };

  return {
    base,
    userInfoForm,
    userInfoRules,
    userInfoList,
    save,
    close,
  };
}
